/*发送AJAX请求*/

let http=new XMLHttpRequest();
//封装的获取节点的方法
function $(temp) {
    let list=document.querySelectorAll(`${temp}`);
    if (list.length===1) {
        return list[0];
    }else {
        return list;
    }
}
//封装的Ajax方法
function AJAX(method,url,callback){
    http.open(method,url);
    http.send();
   //console.log(http.readyState)
    http.onreadystatechange =function (){
        if (http.readyState === 4) {
            callback();
            //Table.init(JSON.parse(xhr.responseText));//反解析将字符串转换为对象
        }
    };
}

//刚进入页面初始化页面
let template=$("#template");

//初始化方法
AJAX("get","http://10.35.164.8:81/SELECTCASE",function () {
    //console.log(JSON.parse(http.responseText));
    JSON.parse(http.responseText).forEach(function (item) {
       // console.log(item)
        let NewLi=template.cloneNode(true);
        NewLi.id="";
        NewLi.querySelector("a").href=`http://10.35.164.8:81/SELECTCASEXQ?id=${item["Case-id"]}`;
        NewLi.querySelector("img").src="img/"+item["Case-img"];
        NewLi.querySelector("p:nth-of-type(1)").innerHTML=item["Case-name"];
        NewLi.querySelector("p:nth-of-type(2)").innerHTML=item["Case-content"];
        NewLi.setAttribute("case-id",item["Case-id"]);
        template.parentNode.insertBefore(NewLi,template);
    })
})